home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Micromail 103 / MicroMail.jar / ProgressForm.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-09-07  |  3.3 KB  |  100 lines

  1. import javax.microedition.lcdui.Command;
  2. import javax.microedition.lcdui.CommandListener;
  3. import javax.microedition.lcdui.Displayable;
  4. import javax.microedition.lcdui.Form;
  5. import javax.microedition.lcdui.Gauge;
  6. import javax.microedition.lcdui.Screen;
  7. import javax.microedition.lcdui.StringItem;
  8.  
  9. public class ProgressForm extends Form implements CommandListener, Runnable {
  10.    private MicroMail midlet;
  11.    private Gauge gauge;
  12.    private StringItem label;
  13.    public static StringItem label2;
  14.    private boolean doDownload;
  15.    Command mainpageCommand = new Command(Resource.getText(1), 2, 1);
  16.    Command cancelCommand = new Command(Resource.getText(31), 2, 1);
  17.  
  18.    public ProgressForm(MicroMail var1, boolean var2) {
  19.       super("");
  20.       this.midlet = var1;
  21.       this.doDownload = var2;
  22.       if (var2) {
  23.          ((Screen)this).setTitle(Resource.getText(45));
  24.       } else {
  25.          ((Screen)this).setTitle(Resource.getText(49));
  26.       }
  27.  
  28.       this.gauge = new Gauge(" ", false, 10, 0);
  29.       ((Form)this).append(this.gauge);
  30.       this.label = new StringItem("", "");
  31.       ((Form)this).append(this.label);
  32.       ((Displayable)this).setCommandListener(this);
  33.       ((Displayable)this).addCommand(this.cancelCommand);
  34.       (new Thread(this)).start();
  35.    }
  36.  
  37.    public void commandAction(Command var1, Displayable var2) {
  38.       if (var1 == this.mainpageCommand) {
  39.          if (this.doDownload) {
  40.             MicroCache.refreshMessageList(1);
  41.             MessageList var3 = new MessageList(this.midlet, 1);
  42.             MicroMail.display.setCurrent(var3);
  43.          } else {
  44.             MicroCache.refreshMessageList(2);
  45.             MessageList var4 = new MessageList(this.midlet, 2);
  46.             MicroMail.display.setCurrent(var4);
  47.          }
  48.  
  49.          MicroMail.dispose(this);
  50.       } else if (var1 == this.cancelCommand) {
  51.          System.out.println("cancel pressed");
  52.          MicroMail.setEndConnection(true);
  53.          this.setInfo(-1, -1, (String)null, Resource.getText(59), (String)null);
  54.       }
  55.  
  56.    }
  57.  
  58.    public void run() {
  59.       if (this.doDownload) {
  60.          int var1 = MailReader.downloadNewMessages(this);
  61.          if (var1 > -1) {
  62.             String var2 = " " + Integer.toString(var1) + Resource.getText(47);
  63.             if (MailReader.tooBigNo > 0) {
  64.                var2 = var2 + "\n " + Integer.toString(MailReader.tooBigNo) + Resource.getText(62);
  65.             }
  66.  
  67.             this.label.setText(var2);
  68.          } else {
  69.             System.out.println("error in downloading");
  70.          }
  71.       } else if (MailSender.sendMail(this)) {
  72.          this.label.setText(Resource.getText(46));
  73.       } else {
  74.          this.label.setText(Resource.getText(50));
  75.       }
  76.  
  77.       ((Displayable)this).addCommand(this.mainpageCommand);
  78.       ((Displayable)this).removeCommand(this.cancelCommand);
  79.    }
  80.  
  81.    public void setInfo(int var1, int var2, String var3, String var4, String var5) {
  82.       if (var1 > -1) {
  83.          this.gauge.setMaxValue(var1);
  84.       }
  85.  
  86.       if (var2 > -1) {
  87.          this.gauge.setValue(var2);
  88.       }
  89.  
  90.       if (var3 != null) {
  91.          this.gauge.setLabel(var3);
  92.       }
  93.  
  94.       if (var4 != null) {
  95.          this.label.setText(var4);
  96.       }
  97.  
  98.    }
  99. }
  100.